package libs.yzx.zaza.acts3;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import libs.yzx.zaza.R;

/**
 * Created by Administrator on 2016/10/14
 */

public class CheckListViewHeaderGoneActivity extends AppCompatActivity{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.actvity_app_bar);

        ListView listview = (ListView) findViewById(R.id.listview);
        final View goneHeader =  findViewById(R.id.goneHeader);

        {
            View header = new View(this);
            header.setBackgroundColor(Color.WHITE);
            header.setLayoutParams(new ListView.LayoutParams(-1,450));
            listview.addHeaderView(header);
        }

        {
            View header = new View(this);
            header.setBackgroundColor(Color.RED);
            header.setLayoutParams(new ListView.LayoutParams(-1,150));
            listview.addHeaderView(header);
        }


        listview.setAdapter(new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,android.R.id.text1,new String[]{
                "1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1",
                "1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1",
                "1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1",
        }));


        listview.setOnScrollListener(new AbsListView.OnScrollListener() {
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                if(firstVisibleItem >0){
                    goneHeader.setVisibility(View.VISIBLE);
                }else
                    goneHeader.setVisibility(View.INVISIBLE);
            }
        });

    }



}
